﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;

namespace Eniux.Windows.ThreeDEngine.Base
{
    partial class EniuxViewport3D
    {
        #region 私有变量
        /// <summary>
        ///  ViewCube名字
        /// </summary>
        private const string PartViewCube = "PART_ViewCube";

        /// <summary>
        /// ViewCube视窗名字
        /// </summary>
        private const string PartViewCubeViewport = "PART_ViewCubeViewport";
        #endregion

        #region 依赖属性


        #region ShowViewCube（是否显示ViewCube）
        /// <summary>
        /// 是否显示ViewCube属性
        /// </summary>
        public static readonly DependencyProperty ShowViewCubeProperty = DependencyProperty.Register(
            "ShowViewCube", typeof(bool), typeof(EniuxViewport3D), new UIPropertyMetadata(true));

        /// <summary>
        /// 获取或设置是否显示ViewCube
        /// </summary>
        public bool ShowViewCube
        {
            get { return (bool)GetValue(ShowViewCubeProperty); }
            set { SetValue(ShowViewCubeProperty, value); }
        } 
        #endregion

        #region FrontViewGesture（前视图操作手势，快捷键：F)）
        /// <summary>
        ///  前视图操作手势属性，快捷键：F
        /// </summary>
        public static readonly DependencyProperty FrontViewGestureProperty =
            DependencyProperty.Register(
                "FrontViewGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.F, ModifierKeys.Control)));

        /// <summary>
        /// 获取或设置前视图操作手势,快捷键：F
        /// </summary>
        public InputGesture FrontViewGesture
        {
            get { return (InputGesture)GetValue(FrontViewGestureProperty); }
            set { SetValue(FrontViewGestureProperty, value); }
        } 
        #endregion

        #region BackViewGesture（后视图操作手势,快捷键：B）
        /// <summary>
        ///  后视图操作手势属性，快捷键：B
        /// </summary>
        public static readonly DependencyProperty BackViewGestureProperty =
            DependencyProperty.Register(
                "BackViewGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.B, ModifierKeys.Control)));

        /// <summary>
        /// 获取或设置后视图操作手势，快捷键：B
        /// </summary>
        public InputGesture BackViewGesture
        {
            get { return (InputGesture)GetValue(BackViewGestureProperty); }
            set { SetValue(BackViewGestureProperty, value); }
        } 
        #endregion

        #region LeftViewGesture(左视图操作手势，快捷键：L)
        /// <summary>
        ///  左视图操作手势属性，快捷键：L
        /// </summary>
        public static readonly DependencyProperty LeftViewGestureProperty =
            DependencyProperty.Register(
                "LeftViewGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.L, ModifierKeys.Control)));

        /// <summary>
        /// 获取或设置左视图操作手势,快捷键：L
        /// </summary>
        public InputGesture LeftViewGesture
        {
            get { return (InputGesture)GetValue(LeftViewGestureProperty); }
            set { SetValue(LeftViewGestureProperty, value); }
        } 
        #endregion

        #region RightViewGesture(右视图操作手势,快捷键：R)
        /// <summary>
        /// 右视图操作手势属性,快捷键：R
        /// </summary>
        public static readonly DependencyProperty RightViewGestureProperty =
            DependencyProperty.Register(
                "RightViewGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.R, ModifierKeys.Control)));

        /// <summary>
        /// 获取或设置右视图操作手势，快捷键：R
        /// </summary>
        public InputGesture RightViewGesture
        {
            get { return (InputGesture)GetValue(RightViewGestureProperty); }
            set { SetValue(RightViewGestureProperty, value); }
        } 
        #endregion

        #region TopViewGesture(顶视图查看手势,快捷键：U)
        /// <summary>
        ///  顶视图查看手势属性,快捷键：U 
        /// </summary>
        public static readonly DependencyProperty TopViewGestureProperty = DependencyProperty.Register(
            "TopViewGesture",
            typeof(InputGesture),
            typeof(EniuxViewport3D),
            new UIPropertyMetadata(new KeyGesture(Key.U, ModifierKeys.Control)));

        /// <summary>
        ///获取或设置顶视图操作手势,快捷键：U
        /// </summary>
        public InputGesture TopViewGesture
        {
            get { return (InputGesture)GetValue(TopViewGestureProperty); }
            set { SetValue(TopViewGestureProperty, value); }
        } 
        #endregion

        #region BottomViewGesture（底视图操作手势,快捷键：D）
        /// <summary>
        ///  底视图操作手势属性，快捷键：D
        /// </summary>
        public static readonly DependencyProperty BottomViewGestureProperty =
            DependencyProperty.Register(
                "BottomViewGesture",
                typeof(InputGesture),
                typeof(EniuxViewport3D),
                new UIPropertyMetadata(new KeyGesture(Key.D, ModifierKeys.Control)));
        /// <summary>
        /// 获取或设置底视图操作手势，快捷键：D
        /// </summary>
        public InputGesture BottomViewGesture
        {
            get { return (InputGesture)GetValue(BottomViewGestureProperty); }
            set { SetValue(BottomViewGestureProperty, value); }
        } 
        #endregion

        #region ViewCubeOpacity（ViewCube透明度）
        /// <summary>
        /// ViewCube透明度属性
        /// </summary>
        public static readonly DependencyProperty ViewCubeOpacityProperty =
            DependencyProperty.Register(
                "ViewCubeOpacity", typeof(double), typeof(EniuxViewport3D), new UIPropertyMetadata(0.5));

        /// <summary>
        /// 获取或设置ViewCube透明度
        /// </summary>
        public double ViewCubeOpacity
        {
            get { return (double)GetValue(ViewCubeOpacityProperty); }
            set { SetValue(ViewCubeOpacityProperty, value); }
        } 
        #endregion

        #endregion

        #region 公共属性
        
        #endregion

        #region 私有方法

        /// <summary>
        /// 当鼠标进入ViewCube视窗时调用此方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewCubeViewportMouseEnter(object sender, MouseEventArgs e)
        {
            AnimateOpacity(this.viewCubeViewport, 1.0, 200);
        }

        /// <summary>
        /// 当鼠标离开ViewCube视窗时调用此方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewCubeViewportMouseLeave(object sender, MouseEventArgs e)
        {
            AnimateOpacity(this.viewCubeViewport, this.ViewCubeOpacity, 200);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="toOpacity"></param>
        /// <param name="animationTime"></param>
        private static void AnimateOpacity(UIElement obj, double toOpacity, double animationTime)
        {
            var a = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime)))
            {
                AccelerationRatio = 0.3,
                DecelerationRatio = 0.5
            };
            obj.BeginAnimation(OpacityProperty, a);
        }
        #endregion
    }
}
